package com.leoman.plz_p.views.enterprise;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.leoman.plz_p.R;
import com.leoman.plz_p.interfaces.LoginView;
import com.leoman.plz_p.module.bean.LoginSuccess;
import com.leoman.plz_p.presenter.LoginPresenter;

import butterknife.Bind;
import butterknife.OnClick;
import cn.com.corelib.base.BaseActivity;
import cn.com.corelib.utils.ToastMgr;
import cn.com.corelib.utils.rxbus.RxBus;

/**
 * Created by guoh on 2018/8/25.
 */
public class LoginActivity extends BaseActivity<LoginView,LoginPresenter>implements LoginView {
    @Bind(R.id.et_number)
    EditText etNumber;
    @Bind(R.id.et_password)
    EditText etPassword;
    @Bind(R.id.et_code)
    EditText etCode;
    @Bind(R.id.tv_code)
    TextView tvCode;
    @Bind(R.id.iv_select)
    ImageView ivSelect;
    @Bind(R.id.tv_login)
    TextView tvLogin;
    @Bind(R.id.tv_weixin)
    TextView tvWeixin;
    @Bind(R.id.tv_qq)
    TextView tvQq;

    public static Intent getLaunchIntent(Context context) {
        return new Intent(context,LoginActivity.class);
    }

    private boolean isSelected=true;

    @Override
    protected int getLayoutId() {
        return R.layout.ac_login;
    }

    @Override
    protected void init(Bundle savedInstanceState) {

    }

    @Override
    protected LoginPresenter createPresenter() {
        return new LoginPresenter();
    }


    @OnClick({R.id.tv_code, R.id.iv_select, R.id.tv_login, R.id.tv_weixin, R.id.tv_qq})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_code:
                getPresenter().getCode();
                break;
            case R.id.iv_select:
                isSelected=!isSelected;
                if (isSelected){
                    ivSelect.setBackgroundResource(R.mipmap.icon_select_on);
                }else {
                    ivSelect.setBackgroundResource(R.mipmap.icon_select_off);
                }
                break;
            case R.id.tv_login:
                getPresenter().login(getText(etNumber),getText(etPassword),getText(tvCode));
//                getPresenter().login("b88888","123123",getText(tvCode));
                break;
            case R.id.tv_weixin:
                ToastMgr.show("微信登录");
//                AuthorityContext.getContext().loggedIn();
//                finish();
                break;
            case R.id.tv_qq:
                ToastMgr.show("QQ登录");
//                AuthorityContext.getContext().loggedIn();
//                finish();
                break;
        }
    }

    @Override
    public void loginSuccess() {
        RxBus.getDefault().send(new LoginSuccess());
        ToastMgr.show("登录成功");
//        startActivity(MainActivity.getLaunchIntent(getViewContext()));
        finish();
    }

    @Override
    public void loginFail() {

    }

    @Override
    public void getCodeSuccess(String code) {
        tvCode.setText(code);
    }


}
